﻿using UnityEngine;
using System.Collections;

public class UVAnimation : MonoBehaviour {
	
	public float fX = 0.0f;
	public float fY = 0.0f;
	public Vector2 vUVDirection = new Vector2(1.0f, 1.0f);
	public float fSpeed = 1.0f;
	public byte  byFlag = 0;
	
	private Vector2 vOffset;
	private Material material;
	
	public short nStop = 0;
	public void IncreaseStop() {
		nStop++;
	}
	public void DecreaseStop() {
		nStop--;
	}
	
	// Use this for initialization
	void Start () {
		material = renderer.material;
		vOffset = material.GetTextureOffset("_MainTex");
	}
	
	// Update is called once per frame
	void Update () {
		if( nStop <= 0 )
		{
			vUVDirection = Vector2.right * fX + Vector2.up *fY;
			vOffset = vOffset + (vUVDirection * Time.deltaTime * fSpeed);
			material.SetTextureOffset("_MainTex", vOffset);
		}
	}
	
	
}
